﻿@model IEnumerable<Von.Web.Models.RightViewModel>

@{
    ViewData["Title"] = "人员权限管理管理";
}
<h2>@ViewBag.User.DisplayName (@ViewBag.User.LoginName)<span>权限管理</span></h2>
<input id="ID" type="hidden" value="@ViewBag.User.ID" />
<div class="container">
    <div id="editor" class="row">
        @foreach (var item in Model)
        {
            <div class="input-group col-md-3" data-von="@item.RoleName">
                <div class="input-group-addon">
                    <input type="checkbox" checked="@item.Checked" />
                </div>
                <span class="form-control">@item.RoleName</span>
            </div>
        }
        <div class="form-group">
            <input value="保存" class="btn btn-default" onclick="Save()" />
        </div>
    </div>
</div>
<script type="text/javascript">
    function Save() {
        var items = $("#editor [data-von]");
        var data = [];
        for (var i = 0; i < items.length; i++) {
            if ($(items[i]).find("input").prop("checked"))
                data.push($(items[i]).find("span").text());
        }
        AjaxPostData('@Url.Ajax("SaveUserRole")', { ID: $("#ID").val(), Roles: data }, function (result) { window.location.replace("/Admin/UserManage"); });
    }
</script>